package com.huanwei.questionfragment.adapter;

import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.huanwei.cc.R;
import com.huanwei.cc.base.Base_Z_Adapter;
import com.huanwei.cc.base.MyApplication;
import com.huanwei.cc.bean.Life_Login_UserInfo;
import com.huanwei.cc.bean.Life_MSG2;
import com.huanwei.cc.db.Z_Login_UserInfoDao;
import com.huanwei.cc.ui.EditTextDialog3;
import com.huanwei.questionfragment.DHD_Activity;
import com.huanwei.questionfragment.Yh_Activity;


/**
 * Created by 他的猫 on 2016/12/3.
 * 待回答适配器
 */

public class RY_Adapter extends Base_Z_Adapter {
    RY_Adapter.Holder holder;
    Yh_Activity activity;
    Z_Login_UserInfoDao z_login_userInfoDao;
    public void setactivity(Yh_Activity activity, Z_Login_UserInfoDao z_login_userInfoDao) {
        this.activity = activity;
        this.z_login_userInfoDao = z_login_userInfoDao;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        // 查找控件
        if (null == convertView) {
            convertView = LayoutInflater.from(MyApplication.getInstance())
                    .inflate(R.layout.item_renyuan, null);
            holder = new RY_Adapter.Holder();
            holder.name = (TextView) convertView
                    .findViewById(R.id.name);
            holder.zhanghao = (TextView) convertView
                    .findViewById(R.id.zhanghao);
            holder.jieyan = (TextView) convertView
                    .findViewById(R.id.jieyan);
            holder.button5 = (Button) convertView
                    .findViewById(R.id.button5);
            // 缓存Holder
            convertView.setTag(holder);
        } else {
            holder = (RY_Adapter.Holder) convertView.getTag();
        }
        final Life_Login_UserInfo teacher = (Life_Login_UserInfo) mDataList.get(position);

        holder.name.setText("姓名："+teacher.getAccount());
        holder.zhanghao.setText("账号"+teacher.getAccount());
        if (teacher.getJinyan().equals("N")) {
            holder.jieyan.setText("是否禁言:否");
        } else {
            holder.jieyan.setText("是否禁言:是");
        }

        holder.button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Life_Login_UserInfo item = (Life_Login_UserInfo) getItem(position);
                String jinyan = item.getJinyan();
                showDialog(jinyan,""+item.getId());
            }
        });
        return convertView;
    }

    public class Holder {
        TextView name;
        TextView zhanghao, jieyan;
        Button button5;


    }
    String xianshi="确定要禁言吗？";
    String key="1";
    String jieyan="N";
    private void showDialog(final String jinyan,final String id) {
        if (jinyan.equals("N")) {
              xianshi="确定要禁言吗？";
            key="1";
            jieyan="Y";
        } else {
            xianshi="确定要解禁吗？";
            key="2";
            jieyan="N";
        }

        android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(activity);
        builder.setTitle("提示");
        builder.setMessage(xianshi);
        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                z_login_userInfoDao.up(jieyan,id);
                activity.shuaxin();

            }
        });
        builder.show();
    }

}
